package com.example.demo.Utils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.alibaba.fastjson.JSON;
/**
 *
 *
 * @author 17996
 */
public class JsonUtil {


    public static String StringClearD(String str){
        String regex = "^,*|,*$";
        String str1 = str.replaceAll(regex, "");
        return str1;
    }


    public static String StringClearDy(String str){

        String str1 = str.replaceAll("\"", "");
        return str1;
    }
    /**
     *
     *  json字符 转list
     * @param str
     * @return
     */
    public static List<Map> JsonStringToList(String str){
        List<Map> listQcPlate = new ArrayList<Map>();
        listQcPlate = JSON.parseArray(str, Map.class);
        return listQcPlate;

    }

    /**
     * json 转String 数组
     * @return
     **/
    public static String[] JsonStringToStringArray(String str){
        List<String> listQcPlate = new ArrayList<>();
        listQcPlate = JSON.parseArray(str, String.class);
        String[] stringArray = new String[listQcPlate.size()];
        for (int i = 0; i < listQcPlate.size(); i++) {
            stringArray[i] = listQcPlate.get(i);

        }
        return  stringArray;
    }

    /**
     *
     *  字符
     * @param str
     * @return
     */
    public static List<Integer> JsonStringToArrary(String str){
        List<Integer> listQcPlate = new ArrayList<Integer>();

        listQcPlate = JSON.parseArray(str, Integer.class);
        return listQcPlate;

    }

    public static List<String> JsonStringToArrary2(String str){
        List<String> listQcPlate = new ArrayList<String>();

        listQcPlate = JSON.parseArray(str, String.class);
        return listQcPlate;

    }


    public static void main(String[] args) {

 /*       String str="[{\"un_prcie\":\"100.00\",\"is_fans_prcie\":\"1\",\"course_type_id\":\"3\"},{\"un_prcie\":\"100.00\",\"is_fans_prcie\":\"0\",\"course_type_id\":\"5\"},{\"un_prcie\":\"100.00\",\"is_fans_prcie\":\"0\",\"course_type_id\":\"10\"}]";
        List<Map> ww = JsonStringToList(str);*/


        String str="[{5,3}]";
        List<Integer> ww = JsonStringToArrary(str);
        System.out.println(ww);
    }
}

